package com.firefly.web.controller.admin.cms;


import com.firefly.web.controller.admin.ConsoleApiRestController;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.dto.cms.CategoryDto;
import com.firefly.dao.dto.cms.CategorySortDto;
import com.firefly.dao.vo.cms.CategoryVo;
import com.firefly.service.command.cms.CategoryCommand;
import com.firefly.service.query.cms.CategoryQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;
import java.util.Map;

/**
 * (Categorys)表控制层
 *
 * @author makejava
 * @since 2022-08-02 08:57:42
 */
@ConsoleApiRestController("category")
public class CategoryController {
    private final CategoryQuery categoryQuery;
    private final CategoryCommand categoryCommand;
    @Autowired
    public CategoryController(CategoryQuery categoryQuery,CategoryCommand categoryCommand){
        this.categoryQuery = categoryQuery;
        this.categoryCommand = categoryCommand;
    }

    @GetMapping("/list")
    public List<Map> getAll() {
        return categoryQuery.tree();
    }

    @GetMapping("/select")
    public List<Map> getSelect() {
        return categoryQuery.select();
    }

    @GetMapping("/detail")
    public CategoryVo getDetail(@Validated(CommonDto.showDetail.class) CommonDto request) {
        return categoryQuery.getDetail(request);
    }

    @PostMapping("/create")
    public Boolean postCreate(@Validated(CategoryDto.create.class) CategoryDto request) {
        return categoryCommand.create(request);
    }

    @PostMapping("/update")
    public Boolean postUpdate(@Validated(CategoryDto.update.class) CategoryDto request) {
        return categoryCommand.update(request);
    }

    @PostMapping("/remove")
    public Boolean postRemove(@Validated(CommonDto.showDetail.class) CommonDto request) {
        return categoryCommand.remove(request);
    }

    @PostMapping("/sort")
    public Boolean postSort(@Validated CategorySortDto request) {
        return categoryCommand.updateSort(request);
    }
}

